package com.unionpay.upyzt.example;

import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.model.TradeBill;
import com.unionpay.upyzt.resp.TradeBillDownloadResp;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

public class TradeBillExample {

    private final LocalDate billDate;

    public TradeBillExample(LocalDate billDate) {
        this.billDate = billDate;
    }

    /**
     * 运行 Demos
     *
     * @return 交易账单下载地址
     */
    public static String runDemos(LocalDate billDate) throws UpyztException {
        TradeBillExample tradeBillExample = new TradeBillExample(billDate);

        // 申请交易账单
        TradeBillDownloadResp tradeBillDownloadResp = tradeBillExample.retrieve();

        return tradeBillDownloadResp.getDownloadUrl();
    }

    /**
     * 申请交易账单
     *
     * @return 返回参数
     */
    public TradeBillDownloadResp retrieve() throws UpyztException {
        Map<String, Object> params = new HashMap<>();
        params.put("bill_date", this.billDate.toString());
        System.out.println("------- 申请交易账单 -------");
        TradeBillDownloadResp resp = TradeBill.getDownloadUrl(params);
        System.out.println(resp);
        return resp;
    }

}
